/* Public interface to generic ringbuffer code */

/* Copyright (C) 2009 David Zanetti
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; version 2 of the License.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */


/* safe write to ringbuffer */
uint8_t ring_write(char *buf, uint8_t *wp, uint8_t mask, char value);
uint8_t ring_write_unsafe(char *buf, uint8_t *wp, uint8_t mask, char value);

/* forced write to ringbuffer - this will always move read pointer if
   we are at the current buffer limit so unprocessed characters are
   dropped */
uint8_t ring_write_force(char *buf, uint8_t *rp, uint8_t *wp,
      			 uint8_t mask, char value);
uint8_t ring_write_force_unsafe(char *buf, uint8_t *rp, uint8_t *wp,
                         uint8_t mask, char value);


/* from the buffer */
char ring_read(char *buf, uint8_t *rp, uint8_t mask);
char ring_read_unsafe(char *buf, uint8_t *rp, uint8_t mask);

/* can we write without hitting limit */
uint8_t ring_writeable(uint8_t rp, uint8_t wp, uint8_t mask);
uint8_t ring_writeable_unsafe(uint8_t rp, uint8_t wp, uint8_t mask);

/* do we have anything yet to be read? */
uint8_t ring_readable(uint8_t rp, uint8_t wp, uint8_t mask);
uint8_t ring_readable_unsafe(uint8_t rp, uint8_t wp, uint8_t mask);


